home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / ifexist.zip / FILEOF.ASM < prev    next >
Assembly Source File  |  1987-10-05  |  5KB  |  118 lines

  1. Title   FileOf  Tests for File Existence - 05 Oct 1987 - Davy Crockett
  2.  
  3. ;       ╔═══╦═══════════════════════════════╦═══╗
  4. ;       ║▒▒▒║   Davy Crockett Productions   ║▒▒▒║
  5. ;       ║▒▒▒║   5807 Cherrywood Lane, 104   ║▒▒▒║
  6. ;       ║▒▒▒║   Greenbelt, Maryland 20770   ║▒▒▒║
  7. ;       ╚═══╩═══════════════════════════════╩═══╝
  8.  
  9. RetNear Macro
  10.         DB      0C3H
  11.         Endm
  12.  
  13. Null    Equ     00H
  14. CR      Equ     0DH
  15. LF      Equ     0AH
  16. Parms   Equ     80H
  17.  
  18. Cseg    Segment
  19.         Assume  DS:Cseg, SS:Cseg, CS:Cseg, ES:Cseg
  20.  
  21.         Org     100H
  22.  
  23. FileOf:
  24.         Mov     BX,Parms                ; point to trailer
  25.         Cmp     Byte Ptr [BX],Null      ; anything there?
  26.         Jnz     GetDefault              ; yes, continue
  27.         Jmp     DisplayHelp             ; no, display help screen
  28.  
  29. GetDefault:
  30.         Mov     AH,19H                  ; function code to
  31.         Int     21H                     ;  obtain default drive
  32.         Add     AL,'A'                  ; adjust to ascii
  33.         Mov     DriveName,AL            ;  and save for later
  34.  
  35.         Mov     SI,Offset 2[Parms]      ; point to trailer
  36.         Mov     DI,Offset DriveName     ; point to buffer
  37.         Cmp     Byte Ptr 1[SI],':'      ; drive included?
  38.         Jz      MoveTrailer             ; yes, use it
  39.         Mov     DI,Offset 2[DriveName]  ; no, use default drive
  40.  
  41. MoveTrailer:
  42.         Lodsb                           ; pick up a byte
  43.         Cmp     AL,CR                   ; end of trailer?
  44.         Jz      TerminateTrailer        ; yes, go make ASCIIZ
  45.         Stosb                           ; no, store this byte
  46.         Jmp     Short   MoveTrailer     ;  and look for more
  47.  
  48. TerminateTrailer:
  49.         Xor     al,al                   ; terminate the string
  50.         Stosb
  51.  
  52. LookForFile:
  53.         Call    Ready                   ; disk in drive?
  54.         Jc      NoDiskExit              ; no, file not found
  55.         Xor     AL,AL                   ; open file for reading
  56.         Mov     DX,Offset DriveName     ; point to path name
  57.         Mov     AH,3DH                  ; open a file function
  58.         Int     21H                     ; try to open it
  59.         Jnc     FoundExit               ; found?
  60.  
  61. NotFoundExit:
  62.         Mov     AL,1                    ; not found return code
  63.         Jmp     Short   FileOfExit      ; exit stage left
  64. DisplayHelp:
  65.         Mov     DX,Offset FileName      ; point to message
  66.         Mov     AH,09H                  ; display string function
  67.         Int     21H                     ; StdOut
  68. NoDiskExit:
  69.         Mov     AL,0                    ; not found return code
  70.         Jmp     Short   FileOfExit      ; exit stage left
  71. FoundExit:
  72.         Push    AX                      ; save file handle
  73.         Pop     BX                      ; retrieve file handle
  74.         Mov     AH,3EH                  ; close file function
  75.         Int     21H                     ; close the file
  76.         Mov     AL,2                    ; found return code
  77. FileOfExit:
  78.         Mov     AH,4CH                  ; terminate a process
  79.         Int     21H                     ; exit stage left
  80.  
  81. Ready:
  82.         Mov     AL,DriveName            ; drive letter
  83.         And     AL,5FH                  ; upper case
  84.         Sub     AL,'A'                  ; adjust to binary
  85.         Mov     BX,Offset DiskBuffer    ; disk buffer address
  86.         Mov     CX,1                    ; number of sectors
  87.         Mov     DX,0                    ; beginning sector number
  88.         Int     25H                     ; absolute disk read
  89.         Pop     BX                      ; remove flags from stack
  90.         RetNear                         ; exit stage right
  91.  
  92. DriveName       DB      '?:'
  93. FileName        Equ     $
  94.                 DB      CR,LF,LF
  95.                 DB      '«*» FileOf «*» Version 1.0 «*» 05 Oct 1987 '
  96.                 DB      '«*» Davy Crockett «*»',CR,LF,LF
  97.                 DB      'Tests for the existence of a File. ',CR,LF,LF
  98.                 DB      '    Execute:  FileOf [pathname]  ',CR,LF,LF
  99. DiskBuffer      Equ     $
  100.                 DB      '    Return Code = 0, no diskie in the drive.',CR,LF
  101.                 DB      '    Return Code = 1, [pathname] does not exist.',CR,LF
  102.                 DB      '    Return Code = 2, [pathname] was found.',CR,LF,LF
  103.                 DB      '$'
  104.  
  105. FileOfLen       Equ     (This Byte) - (Offset FileOf)
  106. Filler          Equ     432 - FileOfLen
  107.                 DB      Filler DUP(0)
  108. CopyRight       Equ     $
  109.                 DB      '╔═════════════╗ '
  110.                 DB      '║Davy Crockett║ '
  111.                 DB      '║ Productions ║ '
  112.                 DB      '║ 05 Oct 1987 ║ '
  113.                 DB      '╚═════════════╝'
  114.  
  115. Cseg    Ends
  116.  
  117.         End     FileOf
  118.